package ua.kpi_java_training.zabrodskyi.module3;

/**
 * Describes each element in the environment.
 * 
 * @author Maksym Zabrodskyi
 * @version 24-Jun-2013
 */
public abstract class Element {

	private Cell cell;

	public Element(Cell cell) {
		if (cell.isBad()) {
			throw new RuntimeException("Error: incorrect cell "
					+ cell.toString());
		}
		this.cell = new Cell(cell);
	}

	/**
	 * Returns a cell in which there is an element.
	 * 
	 * @return cell.
	 */
	public Cell getCell() {
		return cell;
	}

	/**
	 * Set up a new cell for an element.
	 * 
	 * @param cell
	 *            - new cell for an element.
	 */
	public void setCell(Cell cell) {
		if (cell.isBad()) {
			throw new RuntimeException("Error: incorrect cell "
					+ cell.toString());
		}
		this.cell = new Cell(cell);
	}

	public abstract ElementType getType();

	/**
	 * Converts an instance of this class in a string.
	 */
	@Override
	public String toString() {
		return String.format(this.getType() + " is on cell %s", this.cell);
	}

}
